package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.auth.model.LoginUser;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.exception.BusException;
import cn.stylefeng.guns.sys.core.exception.enums.BusExceptionEnum;
import cn.stylefeng.guns.sys.core.properties.SysConfig;
import cn.stylefeng.guns.sys.modular.system.entity.*;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.ProjectTaskEnum;
import cn.stylefeng.guns.sys.modular.system.mapper.ProjectMapper;
import cn.stylefeng.guns.sys.modular.system.mapper.TaskMapper;
import cn.stylefeng.guns.sys.modular.system.mapper.TaskStatusMapper;
import cn.stylefeng.guns.sys.modular.system.mapper.UserMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.TaskFlowParam;
import cn.stylefeng.guns.sys.modular.system.model.params.TaskStatusParam;
import cn.stylefeng.guns.sys.modular.system.model.result.TaskStatusResult;
import cn.stylefeng.guns.sys.modular.system.service.DictService;
import cn.stylefeng.guns.sys.modular.system.service.ProjectService;
import cn.stylefeng.guns.sys.modular.system.service.TaskFlowService;
import cn.stylefeng.guns.sys.modular.system.service.TaskStatusService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 任务状态确认表 服务实现类
 * </p>
 *
 * @author jiangge
 * @since 2020-09-10
 */
@Service
public class TaskStatusServiceImpl extends ServiceImpl<TaskStatusMapper, TaskStatus> implements TaskStatusService {

    @Resource
    private TaskMapper taskMapper;
    @Resource
    private ProjectMapper projectMapper;
    @Resource
    private TaskFlowService taskFlowService;
    @Resource
    private ProjectService projectService;
    @Resource
    private TaskStatusMapper taskStatusMapper;
    @Resource
    private UserMapper userMapper;
    @Resource
    private SysConfig sysConfig;
    @Resource
    private DictService dictService;

    @Override
    public void add(TaskStatusParam param){
        if(ToolUtil.isEmpty(param.getTaskName())){
            Task task = taskMapper.selectById(param.getTaskId());
            param.setTaskName(task.getName());
        }
        TaskStatus entity = getEntity(param);
        if (ToolUtil.isEmpty(param.getCreateUser())){

            LoginUser loginuser = LoginContextHolder.getContext().getUser();
            entity.setCreateId(loginuser.getId());
            entity.setCreateName(loginuser.getName());
        }else {
            entity.setCreateId(param.getCreateUser());
            //根据userID查询name
            String userName = userMapper.getName(param.getCreateUser());
            entity.setCreateName(userName);
        }

//        LoginUser loginuser = LoginContextHolder.getContext().getUser();
//        entity.setCreateId(loginuser.getId());
//        entity.setCreateName(loginuser.getName());
        this.save(entity);
    }

    @Override
    public void addH5(TaskStatusParam param,Long userId){
        if(ToolUtil.isEmpty(param.getTaskName())){
            Task task = taskMapper.selectById(param.getTaskId());
            param.setTaskName(task.getName());
        }
        TaskStatus entity = getEntity(param);
        if (ToolUtil.isEmpty(param.getCreateUser())){

            User user=userMapper.selectById(userId);
            if(ToolUtil.isNotEmpty(user)){
                entity.setCreateId(userId);
                entity.setCreateName(user.getName());
            }

        }else {
            entity.setCreateId(param.getCreateUser());
            //根据userID查询name
            String userName = userMapper.getName(param.getCreateUser());
            entity.setCreateName(userName);
        }
        this.save(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData audit(TaskStatusParam param){
        Task task = taskMapper.selectById(param.getTaskId());
        param.setTaskName(task.getName());
        TaskStatus entity = getEntity(param);
          if(entity.getStatus()==0){
              TaskStatusParam p=new TaskStatusParam();
              p.setProId(entity.getProId());
              p.setTaskIds(entity.getTaskId().toString());
              baseMapper.deleteSt(p);
          }
        //查询是否重复提交
        boolean exist = isExist(entity);
        if(exist){
            return ResponseData.error("已提交，不能重复提交");
        }

        if (ToolUtil.isNotEmpty(param.getCreateUser())){
            entity.setCreateId(param.getCreateUser());
            //根据userID查询name
            String userName = userMapper.getName(param.getCreateUser());
            entity.setCreateName(userName);
        }else {
            LoginUser loginuser = LoginContextHolder.getContext().getUser();
            entity.setCreateId(loginuser.getId());
            entity.setCreateName(loginuser.getName());
        }

        int count = baseMapper.selectStau(entity);
        int savest = 0;
        if (count == 0){
            //新增
            savest=baseMapper.insertSta(entity);
        }else {
            //修改
            savest=baseMapper.updateAuditSt(entity);
        }

        //保存流水记录
        TaskFlowParam flow=new TaskFlowParam();
        flow.setProId(param.getProId());
        flow.setTaskId(param.getTaskId());
        flow.setTaskName(task.getName());
        flow.setStatus(param.getStatus());
        if (ToolUtil.isNotEmpty(param.getCreateUser())){
            flow.setCreateUser(param.getCreateUser());
        }else {
            flow.setCreateUser(LoginContextHolder.getContext().getUser().getId());
        }
        taskFlowService.add(flow);

//        5	 工程总监确认 6	 开发总监确认7	 营运总监确认
        if(5==param.getTaskId()&&(param.getStatus()==BusConst.NOPASS)){
            TaskStatusParam p=new TaskStatusParam();
            p.setProId(param.getProId());
            p.setTaskIds("2");
            int i = baseMapper.deleteSt(p);
            //5的状态-1更改为0
            int i2 = updateStatus2(param);
            if(i>0){
                //通知开发人员
                projectService.pushMsg2KFRY(param.getProId(),param.getTaskId(),entity);
                projectService.pushMsg2GCZJ(param.getProId(),entity);//通知其他工程总监
                projectService.pushMsg2KFZJ(param.getProId(),entity);//通知开发总监
            }else{
                throw new BusException(BusExceptionEnum.Err_UPDATE_STATUS);
            }
        }else if(6==param.getTaskId()&&(param.getStatus()==BusConst.NOPASS)){
            TaskStatusParam p=new TaskStatusParam();
            p.setProId(param.getProId());
            p.setTaskIds("3");
            int i = baseMapper.deleteSt(p);
            //6的状态-1更改为0
            int i2 = updateStatus2(param);
            if(i>0) {
                //通知开发人员
                projectService.pushMsg2KFRY(param.getProId(), param.getTaskId(), entity);
            }else{
                throw new BusException(BusExceptionEnum.Err_UPDATE_STATUS);
            }
        }
        //开发区域经理驳回
        else if(62==param.getTaskId()&&(param.getStatus()==BusConst.NOPASS)){
            TaskStatusParam p=new TaskStatusParam();
            p.setProId(param.getProId());
            p.setTaskIds("3");
            int i = baseMapper.deleteSt(p);
            //6的状态-1更改为0
            int i2 = updateStatus2(param);
            if(i>0) {
                //通知开发人员
                projectService.pushMsg2KFRY(param.getProId(), param.getTaskId(), entity);
            }else{
                throw new BusException(BusExceptionEnum.Err_UPDATE_STATUS);
            }
        }
        else if(7==param.getTaskId()&&(param.getStatus()==BusConst.NOPASS)){
//            TaskStatusParam p=new TaskStatusParam();
//            p.setProId(param.getProId());
//            p.setTaskIds("2,3,5,6");
//            baseMapper.deleteSt(p);
            //更新工程状态
            Project pp = new Project();
            pp.setStatus(BusConst.NOPASS);
            pp.setId(param.getProId());
            int b = projectMapper.updateById(pp);
            //7的状态-1更改为0
            int i2 = updateStatus2(param);
            if(b>0){
                //通知开发人员
                projectService.pushMsg2KFRY(param.getProId(),param.getTaskId(),entity);
                projectService.pushMsg2KFZJ(param.getProId(),entity);
                projectService.pushMsg2GCZJ(param.getProId(),entity);
            }else{
                throw new BusException(BusExceptionEnum.Err_UPDATE_STATUS);
            }
        }else{
            if(savest>0){
                if(5==param.getTaskId()||6==param.getTaskId()){
                    //通知开发人员
//                    projectService.pushKFRY(param.getProId(),param.getTaskId(),entity);
                    projectService.pushMsg2KFRY(param.getProId(),param.getTaskId(),entity);
                    projectService.pushMsg2YYZJ(param.getProId(),entity);//推送营运总监
                    if(5==param.getTaskId()){//通知其他工程总监
                        projectService.pushMsg2KFZJ(param.getProId(),entity);//通知开发总监
                        projectService.pushMsg2GCZJ(param.getProId(),entity);
                    }else{
                        projectService.pushMsg2GCZJ(param.getProId(),entity);//开发总监确认通过后+ 判断工程条件提交-->向工程总监推送消息。
                    }
                }else if(7==param.getTaskId()){//营运总监通过
                    Dict dict = dictService.getOne(new QueryWrapper<Dict>().eq("code", "GC_YAOMA_AUTO"));
                    String val=(dict!=null?dict.getName():"");
                    if("1".equals(val)){
                        projectService.setYaoma(param.getProId());
                    }

                    //通知开发人员
                    projectService.pushKFRY(param.getProId(),param.getTaskId(),entity);
//                    projectService.pushMsg2KFRY(param.getProId(),param.getTaskId(),entity);
                    projectService.pushMsg2KFZJ(param.getProId(),entity);
                    projectService.pushMsg2GCZJ(param.getProId(),entity);
                }
                //开发区域经理通过,推送消息给开发人员和开发总监
                else if(62==param.getTaskId()){
                    //通知开发人员
                    projectService.pushKFRY(param.getProId(),param.getTaskId(),entity);
                    projectService.pushMsg2KFZJ(param.getProId(),entity);
                }

                insertNextNode(param);//插入下个节点
            }
        }
        return ResponseData.success();

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData auditH5(TaskStatusParam param,Long userId){
        Task task = taskMapper.selectById(param.getTaskId());
        param.setTaskName(task.getName());
        TaskStatus entity = getEntity(param);

        //查询是否重复提交
        boolean exist = isExist(entity);
        if(exist&&entity.getStatus()!=0){
            return ResponseData.error(503,"已提交，不能重复提交");
        }

        if (ToolUtil.isNotEmpty(param.getCreateUser())){
            entity.setCreateId(param.getCreateUser());
            //根据userID查询name
            String userName = userMapper.getName(param.getCreateUser());
            entity.setCreateName(userName);
        }else {
            User user =userMapper.selectById(userId);
            if(ToolUtil.isNotEmpty(user)) {
                entity.setCreateId(userId);
                entity.setCreateName(user.getName());
            }
        }

        int count = baseMapper.selectStau(entity);
        int savest = 0;
        if (count == 0){
            //新增
            savest=baseMapper.insertSta(entity);
        }else {
            //修改
            savest=baseMapper.updateAuditSt(entity);
        }

        //保存流水记录
        TaskFlowParam flow=new TaskFlowParam();
        flow.setProId(param.getProId());
        flow.setTaskId(param.getTaskId());
        flow.setTaskName(task.getName());
        flow.setStatus(param.getStatus());
        if (ToolUtil.isNotEmpty(param.getCreateUser())){
            flow.setCreateUser(param.getCreateUser());
        }else {
            flow.setCreateUser(userId);
        }
        taskFlowService.add(flow);

//        5	 工程总监确认 6	 开发总监确认7	 营运总监确认
        if(5==param.getTaskId()&&(param.getStatus()==BusConst.NOPASS)){
            TaskStatusParam p=new TaskStatusParam();
            p.setProId(param.getProId());
            p.setTaskIds("2");
            //p.setTaskIds("2,3,6");
            int i = baseMapper.deleteSt(p);
            //5的状态-1更改为0
            int i2 = updateStatus2(param);
            if(i>0){
                //通知开发人员
                projectService.pushMsg2KFRYH5(param.getProId(),param.getTaskId(),entity,userId);
                projectService.pushMsg2GCZJH5(param.getProId(),entity,userId);//通知其他工程总监
            }else{
                throw new BusException(BusExceptionEnum.Err_UPDATE_STATUS);
            }
        }else if(6==param.getTaskId()&&(param.getStatus()==BusConst.NOPASS)){
            TaskStatusParam p=new TaskStatusParam();
            p.setProId(param.getProId());
            p.setTaskIds("3");
            //p.setTaskIds("3,5");
            int i = baseMapper.deleteSt(p);
            //6的状态-1更改为0
            int i2 = updateStatus2(param);
            if(i>0) {
                //通知开发人员
                projectService.pushMsg2KFRYH5(param.getProId(), param.getTaskId(), entity,userId);
            }else{
                throw new BusException(BusExceptionEnum.Err_UPDATE_STATUS);
            }
        }else if(7==param.getTaskId()&&(param.getStatus()==BusConst.NOPASS)){
            //更新工程状态
            Project pp = new Project();
            pp.setStatus(BusConst.NOPASS);
            pp.setId(param.getProId());
            int b = projectMapper.updateById(pp);
            //7的状态-1更改为0
            int i2 = updateStatus2(param);
            if(b>0){
                //通知开发人员
                projectService.pushMsg2KFRYH5(param.getProId(),param.getTaskId(),entity,userId);
                projectService.pushMsg2KFZJH5(param.getProId(),entity,userId);
                projectService.pushMsg2GCZJH5(param.getProId(),entity,userId);
            }else{
                throw new BusException(BusExceptionEnum.Err_UPDATE_STATUS);
            }
        }else{
            if(savest>0){
                if(5==param.getTaskId()||6==param.getTaskId()){
                    //通知开发人员
                    projectService.pushMsg2KFRYH5(param.getProId(),param.getTaskId(),entity,userId);
                    projectService.pushMsg2YYZJH5(param.getProId(),entity,userId);//推送营运总监
                    if(5==param.getTaskId()){//通知其他工程总监
                        projectService.pushMsg2GCZJH5(param.getProId(),entity,userId);
                    }else{
                        projectService.pushMsg2GCZJH5(param.getProId(),entity,userId);//开发总监确认通过后+ 判断工程条件提交-->向工程总监推送消息。
                    }
                }else if(7==param.getTaskId()){//营运总监通过
                    Dict dict = dictService.getOne(new QueryWrapper<Dict>().eq("code", "GC_YAOMA_AUTO"));
                    String val=(dict!=null?dict.getName():"");
                    if("1".equals(val)){
                        projectService.setYaoma(param.getProId());
                    }

                    //通知开发人员
                    projectService.pushKFRYH5(param.getProId(),param.getTaskId(),entity,userId);
                    projectService.pushMsg2KFZJH5(param.getProId(),entity,userId);
                    projectService.pushMsg2GCZJH5(param.getProId(),entity,userId);
                }
                insertNextNodeH5(param,userId);//插入下个节点
            }
        }
        return ResponseData.success();

    }

    @Override
    public boolean isexist(Integer proId, String taskids) {
        String[] split = taskids.split(",");
        List<TaskStatus> list = this.listBytaskids(proId, taskids);
        if (list.size() == split.length) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData adminAudit(TaskStatusParam param){
        Task task = taskMapper.selectById(param.getTaskId());
        param.setTaskName(task.getName());
        TaskStatus entity = getEntity(param);
        boolean isexist;
        if(5==param.getTaskId()){
            isexist = isexist(param.getProId(), "2");
            if(!isexist){
                return ResponseData.error("工程条件未提交,不允许审核");
            }
        }else if(6==param.getTaskId()){
            isexist = isexist(param.getProId(), "3");
            if(!isexist){
                return ResponseData.error("商务条件未提交,不允许审核");
            }
        }else if(7==param.getTaskId()){
            isexist = isexist(param.getProId(), "5,6");
            if(!isexist){
                return ResponseData.error("开发总监或工程总监未确认");
            }
        }

        //查询是否重复提交
        boolean exist = isExist(entity);
        if(exist){
            return ResponseData.error("已提交，不能重复提交");
        }
        LoginUser loginuser = LoginContextHolder.getContext().getUser();
        entity.setCreateId(loginuser.getId());
        entity.setCreateName(loginuser.getName());
        int count = baseMapper.selectStau(entity);
        int savest = 0;
        if (count == 0){
            //新增
            savest=baseMapper.insertSta(entity);
        }else {
            //修改
            savest=baseMapper.updateAuditSt(entity);
        }

        //保存流水记录
        TaskFlowParam flow=new TaskFlowParam();
        flow.setProId(param.getProId());
        flow.setTaskId(param.getTaskId());
        flow.setTaskName(task.getName());
        flow.setStatus(param.getStatus());
        flow.setCreateUser(LoginContextHolder.getContext().getUser().getId());
        taskFlowService.add(flow);

//        5	 工程总监确认 6	 开发总监确认7	 营运总监确认
        if(5==param.getTaskId()&&(param.getStatus()==BusConst.NOPASS)){
            TaskStatusParam p=new TaskStatusParam();
            p.setProId(param.getProId());
            p.setTaskIds("2,3,6");
            int i = baseMapper.deleteSt(p);
            //5的状态-1更改为0
            int i2 = updateStatus2(param);
            if(i>0){
                //通知开发人员
                projectService.pushMsg2KFRYadmin(param.getProId(),param.getTaskId(),entity);
                projectService.pushMsg2GCZJadmin(param.getProId(),entity);//通知其他工程总监
                projectService.pushMsg2KFZJadmin(param.getProId(),entity);//通知开发总监
            }else{
                throw new BusException(BusExceptionEnum.Err_UPDATE_STATUS);
            }
        }else if(6==param.getTaskId()&&(param.getStatus()==BusConst.NOPASS)){
            TaskStatusParam p=new TaskStatusParam();
            p.setProId(param.getProId());
            p.setTaskIds("3,5");
            int i = baseMapper.deleteSt(p);
            //6的状态-1更改为0
            int i2 = updateStatus2(param);
            //update(param);
            param.setCreateId(LoginContextHolder.getContext().getUserId());
            param.setCreateName(LoginContextHolder.getContext().getUser().getName());
            updateByProId(param);
            if(i>0) {
                //通知开发人员
                projectService.pushMsg2KFRYadmin(param.getProId(), param.getTaskId(), entity);
            }else{
                throw new BusException(BusExceptionEnum.Err_UPDATE_STATUS);
            }
        }else if(7==param.getTaskId()&&(param.getStatus()==BusConst.NOPASS)){
//            TaskStatusParam p=new TaskStatusParam();
//            p.setProId(param.getProId());
//            p.setTaskIds("2,3,5,6");
//            baseMapper.deleteSt(p);
            //更新工程状态
            Project pp = new Project();
            pp.setStatus(BusConst.NOPASS);
            pp.setId(param.getProId());
            int b = projectMapper.updateById(pp);
            //7的状态-1更改为0
            int i2 = updateStatus2(param);
            if(b>0){
                //通知开发人员
                projectService.pushMsg2KFRYadmin(param.getProId(),param.getTaskId(),entity);
                projectService.pushMsg2KFZJadmin(param.getProId(),entity);
                projectService.pushMsg2GCZJadmin(param.getProId(),entity);
            }else{
                throw new BusException(BusExceptionEnum.Err_UPDATE_STATUS);
            }
        }else{
            if(savest>0){
                if(5==param.getTaskId()||6==param.getTaskId()){
                    //通知开发人员
                    projectService.pushMsg2KFRYadmin(param.getProId(),param.getTaskId(),entity);
                    projectService.pushMsg2YYZJadmin(param.getProId(),entity);//推送营运总监
                    if(5==param.getTaskId()){//通知其他工程总监
                        projectService.pushMsg2GCZJadmin(param.getProId(),entity);
                        projectService.pushMsg2KFZJadmin(param.getProId(),entity);//通知开发总监
                    }else{
                        projectService.pushMsg2GCZJadmin(param.getProId(),entity);//开发总监确认通过后+ 判断工程条件提交-->向工程总监推送消息。
                    }
                }else if(7==param.getTaskId()){//营运总监通过
                    //自动生成妖码
                    Dict dict = dictService.getOne(new QueryWrapper<Dict>().eq("code", "GC_YAOMA_AUTO"));
                    String val=(dict!=null?dict.getName():"");
                    if("1".equals(val)){
                        projectService.setYaoma(param.getProId());
                    }

                    //通知开发人员
                    projectService.pushMsg2KFRYadmin(param.getProId(),param.getTaskId(),entity);
                    projectService.pushMsg2KFZJadmin(param.getProId(),entity);
                    projectService.pushMsg2GCZJadmin(param.getProId(),entity);
                }
            }
        }
        return ResponseData.success();

    }

    @Override
    public void delete(TaskStatusParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TaskStatusParam param){
        TaskStatus oldEntity = getOldEntity(param);
        TaskStatus newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);

        this.updateById(newEntity);
    }

    @Override
    public void updateByProId(TaskStatusParam param) {
        baseMapper.updateByProId(param);
    }

    @Override
    public TaskStatusResult findBySpec(TaskStatusParam param){
        return null;
    }

    @Override
    public List<TaskStatusResult> findListBySpec(TaskStatusParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaskStatusParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TaskStatusParam param){
        return null;
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaskStatus getOldEntity(TaskStatusParam param) {
        return this.getById(getKey(param));
    }

    private TaskStatus getEntity(TaskStatusParam param) {
        TaskStatus entity = new TaskStatus();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    @Override
    public List<TaskStatus> listBytaskids(Integer proId, String taskIds){
        return this.baseMapper.listBytaskids(proId,taskIds);
    }
    @Override
    public List<TaskStatus> listProjectFinish(Integer proId){
        return this.baseMapper.listProjectFinish(proId);
    }

    @Override
    public List<TaskStatus> listTaskStatus(){
        return this.baseMapper.listTaskStatus();
    }
    /**
     * 查询状态表数据
     * @param taskId
     * @return
     */
    @Override
    public List<TaskStatus> select(Integer taskId) {
        return taskStatusMapper.select(taskId);
    }

    @Override
    public List<TaskStatus> selectYy(Integer taskId) {
        return taskStatusMapper.selectYy(taskId);
    }

    @Override
    public List<Integer> listAuditFinish(String taskIds) {
        return taskStatusMapper.listAuditFinish(taskIds,taskIds.split(",").length);
    }

    @Override
    public int selectSta(TaskStatusParam param){
        TaskStatus entity = getEntity(param);
        return this.baseMapper.selectSta(entity);
    }

    @Override
    public int selectStau(TaskStatusParam param){
        TaskStatus entity = getEntity(param);
        return this.baseMapper.selectStau(entity);
    }

    @Override
    public int updateAuditSt(TaskStatusParam param){
        TaskStatus entity = getEntity(param);
        return this.baseMapper.updateAuditSt(entity);
    }

    @Override
    public boolean isExist(TaskStatus entity){
        int count = this.baseMapper.isExist(entity);
        return count>0?true:false;
    }

    @Override
    public List<Integer> getTaskByRole(List<Long> rolelist){
        return this.baseMapper.getTaskByRole(rolelist);
    }

    public int updateStatus2(TaskStatusParam param){
        return this.baseMapper.updateStatus2(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertNextNode(TaskStatusParam param){
        if(ToolUtil.isOneEmpty(param.getProId(),param.getTaskId())){
            throw new BusException(BusExceptionEnum.ERR_MISS_PARAM);
        }
        ProjectTaskEnum curtNode = ProjectTaskEnum.getByCode(param.getTaskId());
        List<TaskStatusParam> todolist=new ArrayList<>();
        switch (curtNode){
            case TASK_1:
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_2.getCode(),param.getCreateUser()));
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_3.getCode(),param.getCreateUser()));
                break;
            case TASK_2:
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_5.getCode(),param.getCreateUser()));
                break;
            case TASK_3:
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_62.getCode(),param.getCreateUser()));
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_6.getCode(),param.getCreateUser()));
                break;
            case TASK_5:
            case TASK_6:
                boolean b=isexist(param.getProId(),ProjectTaskEnum.TASK_5.getCode()+","+ProjectTaskEnum.TASK_6.getCode());
                if(b){
                    todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_7.getCode(),param.getCreateUser()));
                }
                break;
            case TASK_7:
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_40.getCode(),param.getCreateUser()));
                break;
            case TASK_40:
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_41.getCode(),param.getCreateUser()));
                break;
            case TASK_41:
                //TODO
                break;
        }

        if(todolist.size()>0){
            for(TaskStatusParam ts:todolist){
                add(ts);
            }
        }

    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertNextNodeH5(TaskStatusParam param,Long userId){
        if(ToolUtil.isOneEmpty(param.getProId(),param.getTaskId())){
            throw new BusException(BusExceptionEnum.ERR_MISS_PARAM);
        }
        ProjectTaskEnum curtNode = ProjectTaskEnum.getByCode(param.getTaskId());
        List<TaskStatusParam> todolist=new ArrayList<>();
        switch (curtNode){
            case TASK_1:
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_2.getCode(),param.getCreateUser()));
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_3.getCode(),param.getCreateUser()));
                break;
            case TASK_2:
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_5.getCode(),param.getCreateUser()));
                break;
            case TASK_3:
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_6.getCode(),param.getCreateUser()));
                break;
            case TASK_5:
            case TASK_6:
                boolean b=isexist(param.getProId(),ProjectTaskEnum.TASK_5.getCode()+","+ProjectTaskEnum.TASK_6.getCode());
                if(b){
                    todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_7.getCode(),param.getCreateUser()));
                }
                break;
            case TASK_7:
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_40.getCode(),param.getCreateUser()));
                break;
            case TASK_40:
                todolist.add(new TaskStatusParam(param.getProId(),ProjectTaskEnum.TASK_41.getCode(),param.getCreateUser()));
                break;
            case TASK_41:
                //TODO
                break;
        }

        if(todolist.size()>0){
            for(TaskStatusParam ts:todolist){
                addH5(ts,userId);
            }
        }

    }

    @Override
    public List<TaskStatus> listReject(){
        return this.baseMapper.listReject();
    }

    /**
     * 取消网上建店
     * @param param
     */
    @Override
    public void deleteWsjd(TaskStatusParam param) {
        param.setTaskId(36);//网上建店
        this.baseMapper.deleteWsjd(param);
    }
}
